<template>
  <div>
    <van-nav-bar
      title="账号登陆"
      left-arrow
      @click-left="onClickLeft"
    />
    <van-form @submit="onSubmit">
      <van-field
        v-model="form.username"
        name=""
        label="用户名"
        placeholder="用户名"
        :rules="rules"
      />
      <van-field
        v-model="form.password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px;">
        <van-button block type="info" native-type="submit">提交</van-button>
      </div>
    </van-form>
    <div class="abc" @click="onSignin">还没有账号，去注册~</div>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  data () {
    return {
      form: {
        username: '',
        password: ''
      },
      rules: [{
        required: true,
        message: '用户名必填',
        pattern: /^\w/
      }]
    }
  },

  created () {

  },

  methods: {
    async onSubmit () {
      try {
        const { data: res } = await axios({
          method: 'POST',
          url: 'http://liufusong.top:8080/user/login',
          data: {
            username: this.form.username,
            password: this.form.password
          }
        })
        console.log(res)
      } catch {
        console.log(123)
      }
    },
    onClickLeft () {
      this.$router.back()
    },
    onSignin () {
      console.log(999)
    }
  }
}
</script>

<style scoped lang='less'>
/deep/.van-nav-bar__content {
  background-color: #16A77A;
  color: #fff;
}
/deep/.van-nav-bar__title {
  color: #fff;
}
/deep/.van-button--info {
  background-color: #0FA376;
  border: 1px solid #0FA376;
}
/deep/.van-icon-arrow-left:before {
  color: #fff;
}
.abc {
  text-align: center;
  color: #9F9699;
}
</style>
